package com.shop.cereshop.business.page.tencent.im;

import com.shop.cereshop.commons.tencent.im.constant.CustomMsgModelType;
import com.shop.cereshop.commons.tencent.im.model.msg.data.CustomMsgData;
import com.shop.cereshop.commons.tencent.im.model.msg.data.CustomMsgDataModel;
import com.shop.cereshop.commons.tencent.im.model.msg.dto.MsgRequestDTO;
import com.shop.cereshop.commons.tencent.im.utils.JsonUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @description: 优惠券消息VO
 * @author zdd
 * @date 2025/11/10
 * @version 1.0
 */
@ApiModel("优惠券消息VO")
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CouponMsgVO implements Serializable {

  private static final long serialVersionUID = 1L;

  @ApiModelProperty("优惠券ID")
  private Long couponId;

  @ApiModelProperty("发送者IM账号")
  private String senderId;

  @ApiModelProperty("接收者IM账号")
  private String receiverId;

  @ApiModelProperty("群组ID")
  private String groupId;

  /**
   * 构建优惠券自定义消息数据（腾讯IM消息格式）
   * 
   * @return 自定义消息数据
   */
  public CustomMsgData covertToCustomMsgData() {
    CustomMsgData msgData = new CustomMsgData();
    msgData.setData(this.covertToMsgData());
    msgData.setDesc("优惠券分享");
    msgData.setExt("");
    msgData.setSound("");
    return msgData;
  }

  /**
   * 构建优惠券自定义消息传输数据
   * 
   * @return 自定义消息传输数据
   */
  public MsgRequestDTO covertToMsgRequestDTO() {
    return MsgRequestDTO.builder()
        .fromAccount(this.senderId)
        .toAccount(this.receiverId)
        .groupId(this.groupId)
        .title("优惠券分享")
        .desc("优惠券分享")
        .build();
  }

  /**
   * 构建优惠券自定义消息体（前端所需）
   * 
   * @return 自定义消息数据
   */
  public String covertToMsgData() {
    CustomMsgDataModel<Object> dataModel = new CustomMsgDataModel<>();
    dataModel.setVersion("1.0");
    dataModel.setType(CustomMsgModelType.COUPON);
    dataModel.setData(this);
    dataModel.setTimestamp(System.currentTimeMillis());
    return JsonUtils.toJson(dataModel);
  }

}
